import React from 'react';
import {Button} from 'antd';
import ServerInfoComtainer from './ServerInfoComtainer';
import DBInfoComtainer from './DBInfoComtainer';
import TableInfoComtainer from './TableInfoComtainer';

class ImageInfoComtainer extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      type: 0,
      data: {},
    };
  }

  render() {
    const ImageInfo = type => {
      if (type == 1) {
        return <ServerInfoComtainer server={this.state.data} />;
      } if (type == 2) {
        return <DBInfoComtainer signal={this.props.signal} db={this.state.data} />;
      } if (type == 3) {
        var tableMeta = null;
        var tableImage = null;
        var columnImages = [];

        for(var i in this.state.data){
          if (this.state.data[i].type == 3) {
            tableImage = this.state.data[i];
            tableMeta = JSON.parse(this.state.data[i].tableMeta);
          } else {
            columnImages.push(this.state.data[i]);
          }
        }
        return <TableInfoComtainer signal={this.props.signal} table={tableImage} tableMeta={tableMeta} columns={columnImages} />;
      } else {
        return;
      }
    };

    const info = ImageInfo(this.state.type);

    return (
      <div>
        {info}
      </div>
    );
  }
}

export default ImageInfoComtainer;

